<?php

declare(strict_types=1);

namespace App\Model;


use App\Utils\MemcacheClient;

/**
 * @property int $id 动态标签ID
 * @property string $title 标签
 * @property string $color 标签颜色
 * @property int $status 状态0禁用 1启用
 */
class TopicTag extends Model
{
    /**
     * The table associated with the model.
     */
    protected ?string $table = 'tb_topic_tags';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = [];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'integer', 'status' => 'integer'];

    /**
     * 获取所有的动态标签列表
     * @return array|mixed
     */
    public static function getAllTopicTagsCache($cache = true)
    {
        // MemcacheClient::getInstance()->delete("topic_tags");
        $tags = MemcacheClient::getInstance()->get("topic_tags");
        if (!$tags || !$cache) {
            $tags = TopicTag::query()->where('status', 1)->get()->toArray();
            MemcacheClient::getInstance()->set("topic_tags", $tags, 3000);
        }
        return $tags;
    }
}
